package Graphique;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.rmi.RemoteException;

import javax.swing.*;

import Client.Client;

public class Fauxlover extends JFrame{
	private static final long serialVersionUID = 1L;

	private Client client;
	
	private JLabel intro = new JLabel("Login de l'utilisateur à fauxlover :");
	private JTextField champsUtilisateur = new JTextField();
	private JButton valider = new JButton("Valider");
	private JButton annuler = new JButton("Annuler"); 
	private ActionListenerChoix alc = new ActionListenerChoix();
	
	public Fauxlover(Client client){
		super("Fauxlover quelqu'un");
		
		this.setSize(250, 250);
		
		valider.addActionListener(alc);
		annuler.addActionListener(alc);
		
		JPanel jp = new JPanel();
		jp.setLayout(new GridLayout(2, 1));
		jp.add(intro);
		jp.add(champsUtilisateur);

		
		JPanel jp2 = new JPanel();
		jp2.setLayout(new GridLayout(1, 2));
		jp2.add(valider);
		jp2.add(annuler);
		
		this.add(jp, BorderLayout.NORTH);
		this.add(jp2, BorderLayout.CENTER);
		this.setLocationRelativeTo(null);
		this.setVisible(true);
		this.pack();
		this.client = client;
	}
	
	private class ActionListenerChoix implements ActionListener {

		@Override
		public void actionPerformed(ActionEvent e) {
			Object obj = e.getSource();
			
			if(valider.equals(obj)){
				try {
					client.fauxlover(champsUtilisateur.getText());
				} catch (RemoteException e1) {
					e1.printStackTrace();
				}
			}
			if(annuler.equals(obj)){
				dispose();
			}
		}
	
	}
}
